function createTable(ID,y,m)
{
	jQuery("#gbox_table"+ID).replaceWith($('<div id="pager'+ID+'"></div><table id="table'+ID+'"></table>'));
	var lastsel2=0;
	var lastsel=0;
	var days=(m!=2?((m%2)^(m>7))+30:(!(y%400)||!(y%4)&&(y%25)?29:28))
	var names=['ID','Название'];
	var cols=[{name:'id',index:'id',key:true, width:60,sortable: false, align:"center", hidden:true},
		   	  {name:'name',index:'name', width:200,sortable: false,editable:false}];
	var dayA=["Вс","Пн","Вт","Ср","Чт","Пт","Сб"];
	for(var i=1;i<=days;i++)

	{

			names[i+1]=""+i+"<br>"+dayA[new Date(y,m-1,i).getDay()];
			cols[i+1]={name:'d'+i,index:'d'+i, width:40,editable:true,sortable: false,editrules:{required:false,integer:true}}
		}
	jQuery("#table"+ID).jqGrid({
	   	url:'/admin/showprice/'+y+'/'+m+'/'+ID,
	    editurl:'/admin/editprice/'+y+'/'+m+'/'+ID,
		datatype: "json",
	    mtype: 'POST',
	   	colNames:names,
	   	colModel:cols,
	   	pager: '#pager'+ID,
	    viewrecords: true,
	    caption:ID,
	    
	    width:"1200",
	    height:"100%"
	});
	jQuery("#table"+ID).jqGrid('navGrid','#pager'+ID,{edit:true,add:false,del:false,search:false});
	$("#table"+ID+" .ui-jqgrid-title").replaceWith('888');
	$("#gbox_table"+ID+" span.ui-jqgrid-title").replaceWith("<div class='editPriceTable' idTable="+ID+"><a href='javascript:void(0)' >Редактировать данные</a></div>");
	$(".editPriceTable").contextMenu({ menu: 'myMenu', leftButton: true },
			function(action, el, pos) { contextMenuWork(action, el, pos); });
}

function createUserTable(idserv,y,m)
{

	//jQuery("#gbox_table"+ID).replaceWith($('<div id="pager'+ID+'"></div><table id="table'+ID+'"></table>'));
	var lastsel2=0;
	var lastsel=0;
	var days=(m!=2?((m%2)^(m>7))+30:(!(y%400)||!(y%4)&&(y%25)?29:28))
	var names=['ID','Название'];
	var cols=[{name:'id',index:'id',key:true, width:1,sortable: false, align:"center", hidden:true},
		   	  {name:'name',index:'name', width:200,sortable: false,editable:false}];
	var dayA=["Вс","Пн","Вт","Ср","Чт","Пт","Сб"];
	for(var i=1;i<=days;i++)
	{
		names[i+1]=""+i+"<br>"+dayA[new Date(y,m-1,i).getDay()];
		cols[i+1]={name:'d'+i,index:'d'+i, width:40,editable:true,sortable: false}
	}
	jQuery("#tableUserPrice").jqGrid({
	   	url:'/admin/showUserPrice/'+y+'/'+m+'/'+idserv,
	   	editurl:'/admin/editUserPrice/'+y+'/'+m+'/'+idserv,
		datatype: "json",
	    mtype: 'POST',
	   	colNames:names,
	   	colModel:cols,
	   	pager: '#pagerUserPrice',
	    viewrecords: true,
	    caption:'AgentPrice',
	     onSelectRow: function (id) {
	                if (id && id !== lastsel2) {

	                   	jQuery('#tableUserPrice').jqGrid('restoreRow', lastsel2);
	                	jQuery('#tableUserPrice').jqGrid('editRow', id, true);
	                    lastsel2 = id;
	                }
	            },
	    width:"1200",
	    height:"100%"
	});
	jQuery("#tableUserPrice").jqGrid('navGrid','#pagerUserPrice',{edit:true,add:false,del:false,search:false});
	
	$("#gbox_tableUserPrice span.ui-jqgrid-title").replaceWith("<div class='editPriceTable' idTable="+idserv+"><a href='javascript:void(0)' >Редактировать данные</a></div>");
	$(".editPriceTable").contextMenu({ menu: 'myMenu', leftButton: true },
			function(action, el, pos) { contextMenuWork(action, el, pos); });

}


   function contextMenuWork(action, el, pos)
   {
   	console.log(location.href);
	   switch (action)
	   {
	   		case "delete":
	   			{
	   				$('#hiddenf2').val($(el).attr('idtable'));
	   				$('.mWindowTestDelete').toggle();
	   				break;
                }
	   		
            case "deletebymonth":
                {
                   	$('#hiddenf3').val($(el).attr('idtable'));
                   	$('.mWindowTestDeleteByMonth').toggle();
                    break;
                }
            case "addprice":
        	{
        		$('#hiddenf1').val($(el).attr('idTable'));
        		$('.editPrice').toggle();
        		break;
            }
          
            }
    }
   

